<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'service-form',
	'enableAjaxValidation'=>true,
	'clientOptions' => array('validateOnSubmit' => true,
   							 'validateOnChange' => false)
)); ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo $form->errorSummary($model); ?>
	
	<!-- Start of Input elements -->
	<fieldset>
		<legend>Customer Details</legend>
		
		<div class="row">
			<?php echo $form->labelEx($model,'firstName'); ?>
			<?php echo $form->textField($model,'firstName',array('size'=>55,'maxlength'=>100)); ?>
			<?php echo $form->error($model,'firstName'); ?>
		</div>
	
		<div class="row">
			<?php echo $form->labelEx($model,'LastName'); ?>
			<?php echo $form->textField($model,'LastName',array('size'=>55,'maxlength'=>100)); ?>
			<?php echo $form->error($model,'LastName'); ?>
		</div>
		
			<div class="row">
			<?php echo $form->labelEx($model,'address'); ?>
			<?php echo $form->textField($model,'address',array('size'=>55,'maxlength'=>255)); ?>
			<?php echo $form->error($model,'address'); ?>
		</div>
	
		<div class="row">
			<?php echo $form->labelEx($model,'suburb'); ?>
			<?php echo $form->textField($model,'suburb',array('size'=>55,'maxlength'=>100)); ?>
			<?php echo $form->error($model,'suburb'); ?>
		</div>
	
		<div class="row">
			<?php echo $form->labelEx($model,'postcode'); ?>
			<?php echo $form->textField($model,'postcode',array('size'=>45,'maxlength'=>45)); ?>
			<?php echo $form->error($model,'postcode'); ?>
		</div>
	
		<div class="row">
			<?php echo $form->labelEx($model,'state'); ?>
			<?php echo $form->dropDownList($model,'state', DataUtil::getStates()); ?>
			<?php echo $form->error($model,'state'); ?>
		</div>
	
		<div class="row">
			<?php echo $form->labelEx($model,'homePhone'); ?>
			<?php echo $form->textField($model,'homePhone',array('size'=>45,'maxlength'=>45)); ?>
			<?php echo $form->error($model,'homePhone'); ?>
		</div>
	
		<div class="row">
			<?php echo $form->labelEx($model,'workPhone'); ?>
			<?php echo $form->textField($model,'workPhone',array('size'=>45,'maxlength'=>45)); ?>
			<?php echo $form->error($model,'workPhone'); ?>
		</div>
	
		<div class="row">
			<?php echo $form->labelEx($model,'mobile'); ?>
			<?php echo $form->textField($model,'mobile',array('size'=>45,'maxlength'=>45)); ?>
			<?php echo $form->error($model,'mobile'); ?>
		</div>
	
		<div class="row">
			<?php echo $form->labelEx($model,'email'); ?>
			<?php echo $form->textField($model,'email',array('size'=>55,'maxlength'=>255)); ?>
			<?php echo $form->error($model,'email'); ?>
		</div>
		
<?php /**<div class="row">
			<?php echo $form->labelEx($model,'stairs'); ?>
			<?php echo $form->dropDownList($model,'stairs',DataUtil::getOptionYesNoEmpty()); ?>
			<?php echo $form->error($model,'stairs'); ?>
		</div>**/?>		

	</fieldset>
	<!-- Customer details end -->
	
	<fieldset>
	<legend>Product Details</legend>
	<div class="row">
	<?php echo CHtml::label("Choose Store",'storeSelector'); ?>
	<?php 
			  $this->widget('zii.widgets.jui.CJuiAutoComplete', array(
			     'name'=>'storeSelector',
			     'sourceUrl'=>array('ajaxSearchStore'),
				 // additional javascript options for the autocomplete plugin
			     'options'=>array(
			         'showAnim'=>'fold',
              		 'minLength'=>2,
                     'select'=>'js:function(event,ui){
                     	$("#Service_storeId").val(ui.item.id);
                     	$("#storeNameCode").html(ui.item.label+" is selected!");
                     }',
				  ),
			      'htmlOptions'=>array(
			      	'style'=>'width:300px;'  
			       ),
			     'value'=>$model->store->name."(".$model->store->code.")",
			  ));
    ?>
    <?php echo $form->hiddenField($model,'storeId'); ?>
    <div class="hint">Input 2 letters of the store name or code to select a store</div>
	</div>

	<div id="storeInfo">
		<div class="row" style="margin-left:160px">
			<?php echo CHtml::tag('span',array('id'=>'storeNameCode'),$model->store->name."(".$model->store->code.")  is selected!");?> 
		</div>
	</div>

	<div class="row">
		<?php echo CHtml::label("Product Type", 'product_type'); ?>
		<?php echo CHtml::dropDownList('product_type', $model->product->type, 
				Product::getProductTypes(),
				array('id'=>'product_type',
					  'ajax' => array(
						'type'=>'POST', //request type
						'url'=>Yii::app()->createUrl('service/ajaxSearchProductNames'), //url to call
						'update'=>'#product_name', //selector to update
						//'data'=>'js:javascript statement'
						//leave out the data key to pass all form values through
					  ),
					  'onchange'=>'$("#Service_productId").html("<option value=\"\" selected=\"selected\"></option>");',
					  'empty'=>'',
				)
			);?>
	</div>
	
	<div class="row">
		<?php echo CHtml::label("Product Name", 'product_name')?>
		<?php echo CHtml::dropDownList('product_name', $model->product->name, 
				DataUtil::getProductNames($model->product->type),
				array('id'=>'product_name',
					  'ajax' => array(
						'type'=>'POST', //request type
						'url'=>Yii::app()->createUrl('service/ajaxSearchProductModels'), //url to call
						'update'=>'#Service_productId', //selector to update
						//'data'=>'js:javascript statement'
						//leave out the data key to pass all form values through
					  )
				)
		);?>
	</div>
	
	<div class="row">
		<?php echo CHtml::label("Product Model", 'Service_productId')?>
		<?php echo $form->dropDownList($model,'productId',
				DataUtil::getProductModels($model->product->type, $model->product->name)); ?>
		<?php echo $form->error($model,'productId',array('hideErrorMessage'=>TRUE)); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'serialNo'); ?>
		<?php echo $form->textField($model,'serialNo',array('size'=>55,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'serialNo'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'purchaseDate'); ?>
		<?php echo $form->hiddenField($model,'purchaseDate'); ?>
		<?php 
		$this->widget('zii.widgets.jui.CJuiDatePicker', array(
		    'name'=>'purchaseDateSelect',
		    'options'=>array(
				'altField'=>'#'.CHtml::activeId($model, "purchaseDate"),				
		    ),
		    'value'=>date("d/m/Y",CDateTimeParser::parse($model->purchaseDate,"yyyy-MM-dd"))		   
		));
		?>
		<?php echo $form->error($model,'purchaseDate'); ?>
	</div>
	
	
	<div class="row">
		<?php echo $form->labelEx($model,'customerAccountNo'); ?>
		<?php echo $form->textField($model,'customerAccountNo',array('size'=>55,'maxlength'=>100)); ?>
		<?php echo $form->error($model,'customerAccountNo'); ?>
	</div>
	
	<div class="row">
		<?php echo $form->labelEx($model,'storeTinNo'); ?>
		<?php echo $form->textField($model,'storeTinNo',array('size'=>55,'maxlength'=>100)); ?>
		<?php echo $form->error($model,'storeTinNo'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'warranty'); ?>
		<?php echo $form->dropDownList($model,'warranty',DataUtil::getOptionYesNo()); ?>
		<?php echo $form->error($model,'warranty'); ?>
	</div>	
	
	<div class="row">
		<?php echo $form->labelEx($model,'faultDescription'); ?>
		<?php echo $form->textArea($model,'faultDescription',array('rows'=>6, 'cols'=>45)); ?>
		<?php echo $form->error($model,'faultDescription'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'otherInstruction'); ?>
		<?php echo $form->textArea($model,'otherInstruction',array('rows'=>6, 'cols'=>45)); ?>
		<?php echo $form->error($model,'otherInstruction'); ?>
	</div>
	</fieldset>

	<!-- Service field Start -->
	<fieldset>
		<legend>Service</legend>

	<div class="row">
		<?php echo $form->labelEx($model,'status'); ?>
		<?php echo $form->dropDownList($model, 'status', Service::getStatusArray());?>
		<?php echo $form->error($model,'status'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'chargeApplicable'); ?>
		<?php echo $form->dropDownList($model, 'chargeApplicable', DataUtil::getOptionYesNoEmpty());?>
		<?php echo $form->error($model,'chargeApplicable'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'customerCharge'); ?>
		<?php echo $form->textField($model,'customerCharge',array('size'=>8,'maxlength'=>8)); ?>
		<?php echo $form->error($model,'customerCharge'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'paymentType'); ?>
		<?php echo $form->dropDownList($model, 'paymentType', ServicePayment::getPaymentTypes());?>
		<?php echo $form->error($model,'paymentType'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'fundsRecovered'); ?>
		<?php echo $form->dropDownList($model, 'fundsRecovered', DataUtil::getOptionYesNo());?>
		<?php echo $form->error($model,'fundsRecovered'); ?>
	</div>
	
	<div class="row">
		<?php echo $form->labelEx($model,'technicianId'); ?>
		<?php 
			switch ($model->status){
				case Service::STATUS_NEW:
				case Service::STATUS_PROCESSING:
					echo "Not Allocated!";
					break;
				case Service::STATUS_JOB_ALLOCATED:
				case Service::STATUS_FINISHED:
					echo $form->dropDownList($model,'technicianId',Installer::getTechnicianList());
			  		echo $form->error($model,'technicianId');
			  		break;
					//echo $model->technician->name;
			}
		?>
	</div>
	
	<div class="row">
		<?php echo $form->labelEx($model,'technicainPaid'); ?>
		<?php echo $form->dropDownList($model, 'technicainPaid', DataUtil::getOptionYesNo()); ?>
		<?php echo $form->error($model,'technicainPaid'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'technicainPaidAmount'); ?>
		<?php echo $form->textField($model,'technicainPaidAmount',array('size'=>8,'maxlength'=>8)); ?>
		<?php echo $form->error($model,'technicainPaidAmount'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'workCarriedOut'); ?>
		<?php echo $form->dropDownList($model, 'workCarriedOut', DataUtil::getOptionYesNo()); ?>
		<?php echo $form->error($model,'workCarriedOut'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'generalComment'); ?>
		<?php echo $form->textArea($model,'generalComment',array('rows'=>6, 'cols'=>45)); ?>
		<?php echo $form->error($model,'generalComment'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'partComment'); ?>
		<?php echo $form->textArea($model,'partComment',array('rows'=>6, 'cols'=>45)); ?>
		<?php echo $form->error($model,'partComment'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'note'); ?>
		<?php echo $form->textArea($model,'note',array('rows'=>6, 'cols'=>45)); ?>
		<?php echo $form->error($model,'note'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'emailNote'); ?>
		<?php echo $form->textArea($model,'emailNote',array('rows'=>6, 'cols'=>45)); ?>
		<?php echo $form->error($model,'emailNote'); ?>
	</div>
	</fieldset>


	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->